package com.hzj.recipe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzj.recipe.entity.Ingredient;
import com.hzj.recipe.entity.Ingredient;
import com.hzj.recipe.mapper.IngredientMapper;
import com.hzj.recipe.service.IngredientService;
import com.hzj.recipe.mapper.IngredientMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author 蜗牛菌
* @description 针对表【ingredient(食材表)】的数据库操作Service实现
* @createDate 2024-01-04 10:49:47
*/
@Service
public class IngredientServiceImpl extends ServiceImpl<IngredientMapper, Ingredient>
    implements IngredientService{

    @Autowired
    private IngredientMapper ingredientMapper;

    @Override
    public Object listAll(Integer index, Integer size, Ingredient ingredient) {
        //默认第一页开始，每页5条
        if(index == null ||index==0){
            index=1;
        }
        if(size==null||size==0){
            size=5;
        }
        Page<Ingredient> pageInfo = new Page(index, size);
        LambdaQueryWrapper<Ingredient> lambdaQueryWrapper = new LambdaQueryWrapper();
        if (ingredient.getIngredientId() != null && ingredient.getIngredientId() != 0 && !Objects.equals(ingredient.getIngredientId(), "")) {
            lambdaQueryWrapper.eq(Ingredient::getIngredientId, ingredient.getIngredientId());
        }
        if ((ingredient.getIngredientName()!=null) && !Objects.equals(ingredient.getIngredientName(), "")) {
            lambdaQueryWrapper.like(Ingredient::getIngredientName, ingredient.getIngredientName());
        }
        if ((ingredient.getIngredientsDescription()!=null) && !Objects.equals(ingredient.getIngredientsDescription(), "")) {
            lambdaQueryWrapper.like(Ingredient::getIngredientsDescription, ingredient.getIngredientsDescription());
        }
        Page<Ingredient> ingredientPage = ingredientMapper.selectPage(pageInfo, lambdaQueryWrapper);

        return ingredientPage;
    }
}




